public class Demo4 {
    public static void main(String[] args) {
        // 给定一个整型数组, 实现冒泡排序(升序排序)
        int[] arr = new int[]{3,5,4,2,7,10,5,2,9,1};
        int n = arr.length;

        // 趟数
        for(int i = 0;i < n - 1;i++){
            boolean flag = true;
            for(int j = 1;j <= n - i - 1;j++){
                if(arr[j-1] > arr[j]){
                    int tmp = arr[j - 1];
                    arr[j - 1] = arr[j];
                    arr[j] = tmp;
                    flag = false;
                }
            }
            if(flag){
                break;
            }
        }

        for(int i = 0;i < n;i++){
            System.out.print(arr[i] + " ");
        }

        System.out.println();
    }
}
